#include<bits/stdc++.h>
using namespace std;
const int N = 20002;
const int M = 100005;

struct Node{
    int x,y,v;
    Node(){}
    Node(int x_,int y_,int v_):x{x_},y{y_},v{v_}{}
    bool operator<(const Node& node)const{
        return v<node.v;
    }
};
int fath[N];
int b[N];
Node nodes[M];
int n,m;

int find(int x){
    if(x==fath[x]) return x;
    int y = find(fath[x]);
    b[x] = (b[fath[x]]^b[x]);
    fath[x] = y;
    return y;
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) fath[i] = i;
    for(int i=1;i<=m;i++){
        int x,y,v;
        scanf("%d%d%d",&x,&y,&v);
        nodes[i] = Node(x,y,v);
    }
    sort(nodes+1,nodes+m+1);
    memset(b,0,sizeof(b));
    for(int i=m;i>0;i--){
        int x = nodes[i].x;
        int y = nodes[i].y;
        int rx = find(x);
        int ry = find(y);
        if(rx!=ry){
            fath[ry] = rx;
            b[ry] = (b[x]-b[y]+1+2)%2;
        }
        else if(b[x]==b[y]){
            printf("%d\n",nodes[i].v);
            return 0;
        }
    }
    printf("0\n");
    return 0;
}